import Mock from 'mockjs'
import {getQuery} from '@/mock/util'

const Random = Mock.Random

export default [
  // 角色管理接口
  {
    url: /\/usermgr\/role\/list/,
    method: 'get',
    data: () => {
      return {
        code: 200,
        data: {
          total: 11,
          list: [
            {
              id: 1,
              created_at: '2025-06-03T10:32:46+08:00',
              updated_at: '0001-01-01T00:00:00Z',
              name: '超级管理员',
              description: '拥有系统全部权限',
              permissionIDs: [
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
                24, 25, 26, 27,
              ],
            },
            {
              id: 2,
              created_at: '2025-06-03T10:32:46+08:00',
              updated_at: '0001-01-01T00:00:00Z',
              name: '普通角色',
              description: '',
              permissionIDs: [2, 3, 4, 5, 6, 7, 8, 17, 20, 22, 23, 25],
            },
            {
              id: 3,
              created_at: '2025-06-03T10:32:46+08:00',
              updated_at: '0001-01-01T00:00:00Z',
              name: '测试角色1',
              description: '测试角色描述1',
              permissionIDs: [],
            },
            {
              id: 4,
              created_at: '2025-06-03T10:32:46+08:00',
              updated_at: '0001-01-01T00:00:00Z',
              name: '测试角色2',
              description: '测试角色描述2',
              permissionIDs: [],
            },
            {
              id: 5,
              created_at: '2025-06-03T10:32:46+08:00',
              updated_at: '0001-01-01T00:00:00Z',
              name: '测试角色3',
              description: '测试角色描述3',
              permissionIDs: [],
            },
            {
              id: 6,
              created_at: '2025-06-03T10:32:46+08:00',
              updated_at: '0001-01-01T00:00:00Z',
              name: '测试角色4',
              description: '测试角色描述4',
              permissionIDs: [],
            },
            {
              id: 7,
              created_at: '2025-06-03T10:32:46+08:00',
              updated_at: '0001-01-01T00:00:00Z',
              name: '测试角色5',
              description: '测试角色描述5',
              permissionIDs: [],
            },
            {
              id: 8,
              created_at: '2025-06-03T10:32:46+08:00',
              updated_at: '0001-01-01T00:00:00Z',
              name: '测试角色6',
              description: '测试角色描述6',
              permissionIDs: [],
            },
            {
              id: 9,
              created_at: '2025-06-03T10:32:46+08:00',
              updated_at: '0001-01-01T00:00:00Z',
              name: '测试角色7',
              description: '测试角色描述7',
              permissionIDs: [],
            },
            {
              id: 10,
              created_at: '2025-06-03T10:32:46+08:00',
              updated_at: '0001-01-01T00:00:00Z',
              name: '测试角色8',
              description: '测试角色描述8',
              permissionIDs: [],
            },
          ],
        },
        msg: '角色列表获取成功',
      }
    },
  },
  {
    url: /\/usermgr\/role\/add/,
    method: 'post',
    data: (config) => {
      const data = JSON.parse(config.body)
      return {
        code: 200,
        data: { ...data, id: Random.id() },
        msg: '角色添加成功',
      }
    },
  },
  {
    url: /\/usermgr\/role\/update/,
    method: 'post',
    data: (config) => {
      const data = JSON.parse(config.body)
      return {
        code: 200,
        data: data,
        msg: '角色更新成功',
      }
    },
  },
  {
    url: /\/usermgr\/role\/permission\/update/,
    method: 'post',
    data: (config) => {
      const data = JSON.parse(config.body)
      return {
        code: 200,
        data: { roleId: data.roleId, permissions: data.permissions },
        msg: '角色权限更新成功',
      }
    },
  },
  {
    url: /\/usermgr\/role\/delete/,
    method: 'get',
    data: (config) => {
      return {
        code: 200,
        data: { },
        msg: '角色删除成功',
      }
    },
  },

  // 用户管理接口
  {
    url: /\/usermgr\/user\/list/,
    method: 'get',
    data: () => {
      return {
        code: 200,
        data: {
          total: 2,
          list: [
            {
              id: 1,
              created_at: '2025-06-03T10:32:46+08:00',
              updated_at: '0001-01-01T00:00:00Z',
              account: 'admin',
              nickname: '超级管理员',
              phone: '12345678901',
              email: 'test@sina.com',
              gender: 0,
              is_admin: 1,
              is_pwd_expired: 0,
              is_active: 0,
              role_name: ['超级管理员'],
            },
            {
              id: 2,
              created_at: '2025-06-03T10:32:46+08:00',
              updated_at: '0001-01-01T00:00:00Z',
              account: 'test',
              nickname: '测试账户',
              phone: '98765432109',
              email: 'test@qq.com',
              gender: 1,
              is_admin: 0,
              is_pwd_expired: 0,
              is_active: 0,
              role_name: ['普通角色'],
            },
          ],
        },
        msg: '用户列表获取成功',
      }
    },
  },
  {
    url: /\/usermgr\/user\/add/,
    method: 'post',
    data: (config) => {
      // const data = JSON.parse(config.body)
      return {
        code: 200,
        data: {},
        msg: '用户添加成功',
      }
    },
  },
  {
    url: /\/usermgr\/user\/update/,
    method: 'post',
    data: (config) => {
      // const data = JSON.parse(config.body)
      return {
        code: 200,
        data: {},
        msg: '用户更新成功',
      }
    },
  },
  {
    url: /\/usermgr\/user\/delete/,
    method: 'get',
    data: (config) => {
      return {
        code: 200,
        data: {},
        msg: '用户删除成功',
      }
    },
  },
  // 权限管理接口
  {
    url: /\/usermgr\/permission\/list/,
    method: 'get',
    data: () => {
      return {
        code: 200,
        data: {
          total: 27,
          list: [
            {
              id: 1,
              parent_id: 0,
              parent_name: '-',
              title: '/',
              code: 'sys',
              type: 0,
              icon: '',
              route_name: 'index',
              route_path: '/',
              route_component: 'Layout',
              children: [
                {
                  id: 2,
                  parent_id: 1,
                  parent_name: '/',
                  title: '仪表盘',
                  code: 'sys:dashboard',
                  type: 0,
                  icon: 'stopwatch',
                  order_num: 1,
                  route_name: 'dashboard',
                  route_path: '/dashboard',
                  route_component: 'RouterView',
                  children: [
                    {
                      id: 3,
                      parent_id: 2,
                      parent_name: '仪表盘',
                      title: '工作台',
                      code: 'sys:dashboard:workplace',
                      type: 1,
                      icon: 'dataBoard',
                      order_num: 1,
                      route_name: 'dashboardWorkplace',
                      route_path: '/dashboard/workplace',
                      route_component: 'dashboard/Workplace.vue',
                    },
                    {
                      id: 4,
                      parent_id: 2,
                      parent_name: '仪表盘',
                      title: '分析页',
                      code: 'sys:dashboard:analysis',
                      type: 1,
                      icon: 'dataAnalysis',
                      order_num: 2,
                      route_name: 'dashboardAnalysis',
                      route_path: '/dashboard/analysis',
                      route_component: 'dashboard/Analysis.vue',
                    },
                  ],
                },
                {
                  id: 5,
                  parent_id: 1,
                  parent_name: '/',
                  title: '用户管理',
                  code: 'sys:usermgr',
                  type: 0,
                  icon: 'user',
                  order_num: 2,
                  route_name: 'usermgr',
                  route_path: '/usermgr',
                  route_component: 'RouterView',
                  children: [
                    {
                      id: 6,
                      parent_id: 5,
                      parent_name: '用户管理',
                      title: '账号',
                      code: 'sys:usermgr:account',
                      type: 1,
                      icon: 'creditCard',
                      order_num: 1,
                      route_name: 'usermgrAccount',
                      route_path: '/usermgr/account',
                      route_component: 'usermgr/User.vue',
                      children: [
                        {
                          id: 16,
                          parent_id: 6,
                          parent_name: '账号',
                          title: '新增',
                          code: 'sys:usermgr:account:add',
                          type: 2,
                          icon: '',
                          order_num: 1,
                          route_name: '',
                          route_path: '',
                          route_component: '',
                        },
                        {
                          id: 17,
                          parent_id: 6,
                          parent_name: '账号',
                          title: '编辑',
                          code: 'sys:usermgr:account:edit',
                          type: 2,
                          icon: '',
                          order_num: 2,
                          route_name: '',
                          route_path: '',
                          route_component: '',
                        },
                        {
                          id: 18,
                          parent_id: 6,
                          parent_name: '账号',
                          title: '删除',
                          code: 'sys:usermgr:account:delete',
                          type: 2,
                          icon: '',
                          order_num: 3,
                          route_name: '',
                          route_path: '',
                          route_component: '',
                        },
                      ],
                    },
                    {
                      id: 7,
                      parent_id: 5,
                      parent_name: '用户管理',
                      title: '角色',
                      code: 'sys:usermgr:role',
                      type: 1,
                      icon: 'cherry',
                      order_num: 2,
                      route_name: 'usermgrRole',
                      route_path: '/usermgr/role',
                      route_component: 'usermgr/Role.vue',
                      children: [
                        {
                          id: 19,
                          parent_id: 7,
                          parent_name: '角色',
                          title: '新增',
                          code: 'sys:usermgr:role:add',
                          type: 2,
                          icon: '',
                          order_num: 1,
                          route_name: '',
                          route_path: '',
                          route_component: '',
                        },
                        {
                          id: 20,
                          parent_id: 7,
                          parent_name: '角色',
                          title: '编辑',
                          code: 'sys:usermgr:role:edit',
                          type: 2,
                          icon: '',
                          order_num: 2,
                          route_name: '',
                          route_path: '',
                          route_component: '',
                        },
                        {
                          id: 21,
                          parent_id: 7,
                          parent_name: '角色',
                          title: '删除',
                          code: 'sys:usermgr:role:delete',
                          type: 2,
                          icon: '',
                          order_num: 3,
                          route_name: '',
                          route_path: '',
                          route_component: '',
                        },
                        {
                          id: 22,
                          parent_id: 7,
                          parent_name: '角色',
                          title: '分配权限',
                          code: 'sys:usermgr:role:permission',
                          type: 2,
                          icon: '',
                          order_num: 4,
                          route_name: '',
                          route_path: '',
                          route_component: '',
                        },
                      ],
                    },
                    {
                      id: 8,
                      parent_id: 5,
                      parent_name: '用户管理',
                      title: '权限',
                      code: 'sys:usermgr:permission',
                      type: 1,
                      icon: 'apple',
                      order_num: 3,
                      route_name: 'usermgrPermission',
                      route_path: '/usermgr/permission',
                      route_component: 'usermgr/Permission.vue',
                      children: [
                        {
                          id: 23,
                          parent_id: 8,
                          parent_name: '权限',
                          title: '新增',
                          code: 'sys:usermgr:permission:add',
                          type: 2,
                          icon: '',
                          order_num: 1,
                          route_name: '',
                          route_path: '',
                          route_component: '',
                        },
                        {
                          id: 24,
                          parent_id: 8,
                          parent_name: '权限',
                          title: '编辑',
                          code: 'sys:usermgr:permission:edit',
                          type: 2,
                          icon: '',
                          order_num: 2,
                          route_name: '',
                          route_path: '',
                          route_component: '',
                        },
                        {
                          id: 25,
                          parent_id: 8,
                          parent_name: '权限',
                          title: '删除',
                          code: 'sys:usermgr:permission:delete',
                          type: 2,
                          icon: '',
                          order_num: 3,
                          route_name: '',
                          route_path: '',
                          route_component: '',
                        },
                      ],
                    },
                  ],
                },
                {
                  id: 9,
                  parent_id: 1,
                  parent_name: '/',
                  title: '系统管理',
                  code: 'sys:system',
                  type: 0,
                  icon: 'grid',
                  order_num: 3,
                  route_name: 'system',
                  route_path: '/system',
                  route_component: 'RouterView',
                  children: [
                    {
                      id: 10,
                      parent_id: 9,
                      parent_name: '系统管理',
                      title: '个人中心',
                      code: 'sys:system:profile',
                      type: 1,
                      icon: 'postcard',
                      order_num: 1,
                      route_name: 'systemProfile',
                      route_path: '/system/profile',
                      route_component: 'system/Profile.vue',
                    },
                    {
                      id: 11,
                      parent_id: 9,
                      parent_name: '系统管理',
                      title: '系统设置',
                      code: 'sys:system:settings',
                      type: 1,
                      icon: 'setting',
                      order_num: 2,
                      route_name: 'systemSettings',
                      route_path: '/system/settings',
                      route_component: 'system/Settings.vue',
                    },
                    {
                      id: 12,
                      parent_id: 9,
                      parent_name: '系统管理',
                      title: 'API管理',
                      code: 'sys:system:api',
                      type: 1,
                      icon: 'magicStick',
                      order_num: 3,
                      route_name: 'systemApi',
                      route_path: '/system/api',
                      route_component: 'system/Api.vue',
                    },
                  ],
                },
                {
                  id: 13,
                  parent_id: 1,
                  parent_name: '/',
                  title: 'DevOps',
                  code: 'sys:devops',
                  type: 0,
                  icon: 'sugar',
                  order_num: 4,
                  route_name: 'devops',
                  route_path: '/devops',
                  route_component: 'RouterView',
                  children: [
                    {
                      id: 14,
                      parent_id: 13,
                      parent_name: 'DevOps',
                      title: '运行日志',
                      code: 'sys:devops:log',
                      type: 1,
                      icon: 'document',
                      order_num: 1,
                      route_name: 'devopsLog',
                      route_path: '/devops/log',
                      route_component: 'devops/Log.vue',
                    },
                    {
                      id: 15,
                      parent_id: 13,
                      parent_name: 'DevOps',
                      title: '服务器状态',
                      code: 'sys:devops:vm',
                      type: 1,
                      icon: 'monitor',
                      order_num: 2,
                      route_name: 'devopsVm',
                      route_path: '/devops/vm',
                      route_component: 'devops/Vm.vue',
                    },
                  ],
                },
                {
                  id: 26,
                  parent_id: 1,
                  parent_name: '/',
                  title: '小工具',
                  code: 'sys:tools',
                  type: 0,
                  icon: 'star',
                  order_num: 5,
                  route_name: 'tools',
                  route_path: '/tools',
                  route_component: 'RouterView',
                  children: [
                    {
                      id: 27,
                      parent_id: 26,
                      parent_name: '小工具',
                      title: '像素图形',
                      code: 'sys:tools:matrix',
                      type: 1,
                      icon: 'picture',
                      order_num: 1,
                      route_name: 'matrix',
                      route_path: '/tools/matrix',
                      route_component: 'tools/Matrix.vue',
                    },
                  ],
                },
              ],
            },
          ],
        },
        msg: '权限列表获取成功',
      }
    },
  },
  {
    url: /\/usermgr\/permission\/tree-list/,
    method: 'get',
    data: (options) => {
      const excludeOperation = getQuery(options.url,'excludeOperation')
      // console.log(excludeOperation)
      if (excludeOperation != null && excludeOperation === 'false') {
        return {
          code: 200,
          msg: '权限树列表获取成功',
          data: [
            {
              label: '/',
              value: 1,
              type: 0,
              children: [
                {
                  label: '仪表盘',
                  value: 2,
                  type: 0,
                  children: [
                    {
                      label: '工作台',
                      value: 3,
                      type: 1,
                    },
                    {
                      label: '分析页',
                      value: 4,
                      type: 1,
                    },
                  ],
                },
                {
                  label: '用户管理',
                  value: 5,
                  type: 0,
                  children: [
                    {
                      label: '账号',
                      value: 6,
                      type: 1,
                      children: [
                        {
                          label: '新增',
                          value: 16,
                          type: 2,
                        },
                        {
                          label: '编辑',
                          value: 17,
                          type: 2,
                        },
                        {
                          label: '删除',
                          value: 18,
                          type: 2,
                        },
                      ],
                    },
                    {
                      label: '角色',
                      value: 7,
                      type: 1,
                      children: [
                        {
                          label: '新增',
                          value: 19,
                          type: 2,
                        },
                        {
                          label: '编辑',
                          value: 20,
                          type: 2,
                        },
                        {
                          label: '删除',
                          value: 21,
                          type: 2,
                        },
                        {
                          label: '分配权限',
                          value: 22,
                          type: 2,
                        },
                      ],
                    },
                    {
                      label: '权限',
                      value: 8,
                      type: 1,
                      children: [
                        {
                          label: '新增',
                          value: 23,
                          type: 2,
                        },
                        {
                          label: '编辑',
                          value: 24,
                          type: 2,
                        },
                        {
                          label: '删除',
                          value: 25,
                          type: 2,
                        },
                      ],
                    },
                  ],
                },
                {
                  label: '系统管理',
                  value: 9,
                  type: 0,
                  children: [
                    {
                      label: '个人中心',
                      value: 10,
                      type: 1,
                    },
                    {
                      label: '系统设置',
                      value: 11,
                      type: 1,
                    },
                    {
                      label: 'API管理',
                      value: 12,
                      type: 1,
                    },
                  ],
                },
                {
                  label: 'DevOps',
                  value: 13,
                  type: 0,
                  children: [
                    {
                      label: '运行日志',
                      value: 14,
                      type: 1,
                    },
                    {
                      label: '服务器状态',
                      value: 15,
                      type: 1,
                    },
                  ],
                },
                {
                  label: '小工具',
                  value: 26,
                  type: 0,
                  children: [
                    {
                      label: '像素图形',
                      value: 27,
                      type: 1,
                    },
                  ],
                },
              ],
            },
          ],
        }
      }
      return {
        code: 200,
        data: [
          {
            label: '/',
            value: 1,
            type: 0,
            children: [
              {
                label: '仪表盘',
                value: 2,
                type: 0,
                children: [
                  {
                    label: '工作台',
                    value: 3,
                    type: 1,
                  },
                  {
                    label: '分析页',
                    value: 4,
                    type: 1,
                  },
                ],
              },
              {
                label: '用户管理',
                value: 5,
                type: 0,
                children: [
                  {
                    label: '账号',
                    value: 6,
                    type: 1,
                  },
                  {
                    label: '角色',
                    value: 7,
                    type: 1,
                  },
                  {
                    label: '权限',
                    value: 8,
                    type: 1,
                  },
                ],
              },
              {
                label: '系统管理',
                value: 9,
                type: 0,
                children: [
                  {
                    label: '个人中心',
                    value: 10,
                    type: 1,
                  },
                  {
                    label: '系统设置',
                    value: 11,
                    type: 1,
                  },
                  {
                    label: 'API管理',
                    value: 12,
                    type: 1,
                  },
                ],
              },
              {
                label: 'DevOps',
                value: 13,
                type: 0,
                children: [
                  {
                    label: '运行日志',
                    value: 14,
                    type: 1,
                  },
                  {
                    label: '服务器状态',
                    value: 15,
                    type: 1,
                  },
                ],
              },
              {
                label: '小工具',
                value: 26,
                type: 0,
                children: [
                  {
                    label: '像素图形',
                    value: 27,
                    type: 1,
                  },
                ],
              },
            ],
          },
        ],
        msg: '权限树列表获取成功',
      }
    },
  },
  {
    url: /\/usermgr\/permission\/add/,
    method: 'post',
    data: (config) => {
      return {
        code: 200,
        data: {},
        msg: '权限添加成功',
      }
    },
  },
  {
    url: /\/usermgr\/permission\/update/,
    method: 'post',
    data: (config) => {
      return {
        code: 200,
        data: {},
        msg: '权限更新成功',
      }
    },
  },
  {
    url: /\/usermgr\/permission\/delete/,
    method: 'get',
    data: (config) => {
      return {
        code: 200,
        data: {},
        msg: '权限删除成功',
      }
    },
  },
]
